package com.boboPlanet.controller;

import com.boboPlanet.comm.rabbitmq.RabbitMqRoutingConfig;
import com.boboPlanet.comm.rabbitmq.producer.PlanetMqTopic;
import com.boboPlanet.comm.result.ResponseResult;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Description: TODO
 * @Author: mis_wu
 * @Date: 2023/4/8
 * @Company 众阳 LIS
 **/
@RestController
public class TestCtl {

    @Value("${server.port}")
    private String port;

    @Resource
    private PlanetMqTopic planetMqTopic;

    @GetMapping("/test")
    public ResponseResult<String> test(){

        planetMqTopic.queue(RabbitMqRoutingConfig.gateway_login_expire_queue)
                .exchange(RabbitMqRoutingConfig.gateway_login_expire_exchange)
                .routingKey(RabbitMqRoutingConfig.gateway_login_expire_routing_key)
                .sendMsg("hello gateway!!!");

        return ResponseResult.isSuccess("当前服务端口："+port);
    }

    public static void main(String[] args) {
        f(0,"abcd");
    }

    /**
     * 给定一个升序数组，查找数组中某个元素，并返回下标，找不到返回-1
     * @param sourceArr 源数组
     * @param target 查找元素
     * @return 返回找到元素的下标
     */
    public static int binarySearchBasic(int [] sourceArr, int target){
        int i = 0, j = sourceArr.length;
        while (i < j){
            // 取i与j的中间下标(向下取整)
            int m = (i + j) >>> 1;
            if (target < sourceArr[m]){
                // 目标值小于中间值，即目标值在左边
                j = m;
            } else if (target > sourceArr[m]) {
                // 目标值大于中间值，即目标值在右边
                i = m + 1;
            }else {
                // 目标值等于中间值，即找到了
                return m;
            }
        }

        return -1;
    }

    private static void f(int n,String str){
        if (n == str.length()){
            return;
        }
        f(n + 1,str);
        System.out.println(str.charAt(n));
    }

}
